//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_facrebuild.sqf"
#include "x_setup.sqf"

private ["_findex", "_wairfac", "_pos", "_dir", "_fac","_timeend"];
PARAMS_1(_findex);
		
switch (_findex) do {
	case 0: {[QGVAR(jet_s_reb),true] call FUNC(NetSetJIP)};
	case 1: {[QGVAR(chopper_s_reb),true] call FUNC(NetSetJIP)};
	case 2: {[QGVAR(wreck_s_reb),true] call FUNC(NetSetJIP)};
};
sleep (300 + (random 300));
_wairfac = switch (GVAR(own_side)) do {
	case "BLUFOR": {GVAR(WarfareAircraftFactory_blufor)};
	case "INDEPENDENT": {GVAR(WarfareAircraftFactory_INDEPENDENT)};
	case "OPFOR": {GVAR(WarfareAircraftFactory_opfor)};
};
_pos = (GVAR(aircraft_facs select _findex)) select 0;
_dir = (GVAR(aircraft_facs select _findex)) select 1;
		
_fac = createVehicle [_wairfac, _pos, [], 0, "NONE"];
_fac setDir _dir;
_fac setPos _pos;
		
switch (_findex) do {
	case 0: {_fac addEventHandler ["killed", {[_this select 0, 0] call FUNC(x_fackilled)}]};
	case 1: {_fac addEventHandler ["killed", {[_this select 0, 1] call FUNC(x_fackilled)}]};
	case 2: {_fac addEventHandler ["killed", {[_this select 0, 2] call FUNC(x_fackilled)}]};
};

switch (_findex) do {
	case 0: {
		[QGVAR(jet_serviceH),false] call FUNC(NetSetJIP);
		[QGVAR(jet_s_reb),false] call FUNC(NetSetJIP);
		GVAR(kb_logic1) kbTell [GVAR(kb_logic2),GVAR(kb_topic_side),"JetServiceRebuilded",true];
	};
	case 1: {
		[QGVAR(chopper_serviceH),false] call FUNC(NetSetJIP);
		[QGVAR(chopper_s_reb),false] call FUNC(NetSetJIP);
		GVAR(kb_logic1) kbTell [GVAR(kb_logic2),GVAR(kb_topic_side),"ChopperServiceRebuilded",true];
	};
	case 2: {
		[QGVAR(wreck_repairH),false] call FUNC(NetSetJIP);
		[QGVAR(wreck_s_reb),false] call FUNC(NetSetJIP);
		GVAR(kb_logic1) kbTell [GVAR(kb_logic2),GVAR(kb_topic_side),"WreckServiceRebuilded",true];
	};
};